# -*- coding: utf-8 -*-
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'TuringClass.settings')
import django
from app_TuringClass.models import *
from app_OnlineExam.models import *
import datetime
import django.utils.timezone as timezone

def population():
	Add_QuestionTag('001', 'C/C++', 'test-20161122')
	Add_QuestionTag('002', '高数', 'test-20161122')
	Add_QuestionTag('003', '线性代数', 'test-20161122')
	Add_QuestionTag('004', '英语', 'test-20161122')
	Add_QuestionTag('005', '语言', 'test-20161122')
	Add_QuestionTag('006', '算法', 'test-20161122')
	Add_QuestionTag('007', '校内事务', 'test-20161122')
	Add_QuestionTag('008', '其他', 'test-20161122')
	
	Add_DefaultQuestion("C语言里exit的作用是什么？", "return，exit，halt有什么差别。放在函数里是返回一层还是结束整个程序？exit(0)，exit(1)是什么意思？", "001", "TuringClass")
	Add_DefaultQuestion("2020年1月1日是星期几？", "请写程序计算出2020年1月1日是星期几.", "001", "TuringClass")
	Add_DefaultQuestion("支持向量机是什么？" ,"请简要介绍出支持向量机是什么.", "006", "TuringClass")
	Add_DefaultQuestion("积分表要背吗？" ,"好多啊，记不下来。但是考试的时候临时算好像又会来不及！", "002", "TuringClass")
	Add_DefaultQuestion("怎么实现精确计算啊？" ,"比如 n<=1000 求2^n的值！", "001", "TuringClass")
	Add_DefaultQuestion("有木有c++手机编程软件？" ,"谁有c++手机编程软件，给我来一发，谢谢！", "001", "TuringClass")
	Add_DefaultQuestion("电脑义诊能给我们带来什么帮助呢？" ,"谁有c++手机编程软件，给我来一发，谢谢！", "007", "TuringClass")

	
def Add_QuestionTag(TagID, TagName, Note):
	print "[TagID] = ",TagID
	if QuestionTag.objects.filter(TagID = TagID).exists():
		print "[TagID has been existed...]"
	else:
		NewQuestionTag = QuestionTag.objects.get_or_create(TagID = TagID, TagName = TagName, Note = Note)[0]
		NewQuestionTag.save()
		print "-- function [Add_QuestionTag] successful... "

def Add_DefaultQuestion(_QuestionAbstract, _QuestionContent, TagsID, QuizzerID):
	print "[Add_DefaultQuestion]...QuestionAbstract = ",_QuestionAbstract
	# QuestionDetails
	_QuestionID = str(len(QuestionDetails.objects.all())+1)
	QuestionDetails(QuestionID = _QuestionID, QuestionAbstract = _QuestionAbstract, QuestionContent = _QuestionContent, QuestionStatus='Approved', TagsID = TagsID, QuizzerID = QuizzerID).save()
	print "[Add_QuestionDetails successful...]"
	# QuestionList
	_QuestionListID = str(len(QuestionList.objects.all())+1)
	QuestionList(LastModifyDate=timezone.now(),QuestionID = _QuestionListID, QuestionAbstract = _QuestionAbstract, QuestionContent = _QuestionContent, TagsID = TagsID, QuizzerID = QuizzerID).save()
	print "[Add_QuestionList successful...]"


### main program
if __name__ == '__main__':
	print 'DatabaseInit.py - running...'
	population()
